import json
import io
import os
from datetime import date, datetime

#json日期格式化
class DateEncoder(json.JSONEncoder):
    
    def default(self,obj):
        if isinstance(obj,datetime):
            return obj.strftime('%Y-%m-%d %H:%M:%S')
        elif isinstance(obj,date):
            return obj.strftime('%Y-%m-%d')
        else:
            return json.JSONEncoder.default(self,obj)


class FileSanner():

    filenames=[]
    def __init__(self):
        pass

    def scanDirectories(self,path,prefix='.jpg'):
        isExists=os.path.exists(path)
        if isExists:
            print('存在')
        else:
            print('不存在')
        pass

    def recursiveDir(self,dirPath):
        files=os.listdir(dirPath)
        index=0
        for file in files:
            fullPath=dirPath+'\\'+file
            if os.path.isfile(fullPath):
                index+=1
                self.filenames.append({'name':file,'index':index})
                print('文件:'+fullPath)
            else:
                print('目录'+fullPath)
                self.recursiveDir(fullPath)
        return self.filenames                
           

if __name__=="__main__":
    scanner=FileSanner()
    print(scanner.recursiveDir("C:\\Users\\Public\\Pictures\\Sample Pictures"))


